/*
Jimmy Manone
Lab 12 Task 01
10/23/14
 */
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include	"inc/hw_ints.h" //Enable hardware interrupts
#include	"driverlib/interrupt.h" //Driverlib for interrupts

void UARTIntHandler(void) //UART Interrupt handler-Echo/blink LED
{
	uint32_t	ui32Status;
	ui32Status	=	UARTIntStatus(UART0_BASE,	true);	//get	interrupt	status
	UARTIntClear(UART0_BASE,	ui32Status);	//clear	the	asserted	interrupts
	while(UARTCharsAvail(UART0_BASE))	//loop	while	there	are	chars
	{
		UARTCharPutNonBlocking(UART0_BASE,	UARTCharGetNonBlocking(UART0_BASE));
		//echo	character
		GPIOPinWrite(GPIO_PORTF_BASE,	GPIO_PIN_2,	GPIO_PIN_2);	//blink	LED
		SysCtlDelay(SysCtlClockGet()	/	(1000	*	3));	//delay	~1	msec
		GPIOPinWrite(GPIO_PORTF_BASE,	GPIO_PIN_2,	0);	//turn	off	LED
	}
}


int main(void) {

	SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
	//Set up the system clock
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); //Enable the UART0 and GPIOA peripherals
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	//Configure the pins for the receiver and transmitter using GPIOPinConfigure
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	//Initialize the parameters for the UART: 115200, 8-1-N

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //Enable LED's
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,	GPIO_PIN_2);

	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
			(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); //configure
	//clock for UART

	IntMasterEnable(); //Enable interrupts
	IntEnable(INT_UART0); //Enable interrupt on UART0
	UARTIntEnable(UART0_BASE,UART_INT_RX|UART_INT_RT); //Receiver interrupts/timeouts


	UARTCharPut(UART0_BASE, 'E');
	UARTCharPut(UART0_BASE, 'n');
	UARTCharPut(UART0_BASE, 't');
	UARTCharPut(UART0_BASE, 'e');
	UARTCharPut(UART0_BASE, 'r'); //Use simple “UARTCharPut()” calls to create a prompt.
	UARTCharPut(UART0_BASE, ' ');
	UARTCharPut(UART0_BASE, 'T');
	UARTCharPut(UART0_BASE, 'e');
	UARTCharPut(UART0_BASE, 'x');
	UARTCharPut(UART0_BASE, 't');
	UARTCharPut(UART0_BASE, ':');
	UARTCharPut(UART0_BASE, ' ');

	while (1)
	{
		/*An infinite loop. In this loop, if there is a character in the receiver,
    	it is read, and then
    	written to the transmitter.
    	This echoes what you type in the terminal window.*/

		//if (UARTCharsAvail(UART0_BASE)) UARTCharPut(UART0_BASE, UARTCharGet(UART0_BASE));
	}

}

